package com.example.home_app.adapter

import android.annotation.SuppressLint
import android.text.TextPaint
import android.text.style.ClickableSpan
import android.view.View
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.example.home_app.R
import com.example.home_app.data.DataServer
import com.example.home_app.util.SbParameter
import com.example.home_app.util.Status
import java.util.*

/**
 *
 * @author dell
 * @date 2021/8/2
 */
class HistoricityADapper(var list: ArrayList<Map<String, Any>>) :
    BaseQuickAdapter<Status, BaseViewHolder>(
        R.layout.history_data_list,
        DataServer.getSampleData(SbParameter.HISTORYLIST)
    ) {
    @SuppressLint("ResourceType")
    protected override fun convert(holder: BaseViewHolder, item: Status) {
        val i = list[holder.layoutPosition]["Value"].toString().toInt()
        if (i == 0) {
            holder.setText(R.id.tweetDate, "设备已开启")
        } else {
            holder.setText(R.id.tweetDate, "设备已关闭")
        }
        holder.setText(R.id.tweetName, "Value:" + list[holder.layoutPosition]["Value"].toString())
        holder.setText(R.id.tweetText, "Date:" + list[holder.layoutPosition]["Time"].toString())
    }


    private val clickableSpan: ClickableSpan = object : ClickableSpan() {
        override fun onClick(widget: View) {}
        override fun updateDrawState(ds: TextPaint) {
            ds.color = context.resources.getColor(R.color.clickspan_color)
            ds.isUnderlineText = true
        }
    }
}